include("shared.lua")
include("cl_HUD.lua")
include("cl_inventory.lua")

function buildweapon( um )
  	local gunderma= vgui.Create("DFrame")
	local button= um:ReadLong()
	local metalamount= um:ReadLong()

	gunderma:SetSize(300,300)
	gunderma:Center()
	gunderma:SetVisible(true)
	gunderma:SetDraggable(false)
	gunderma:SetTitle("Create Weapons")
	gunderma:MakePopup()

	local metal=vgui.Create("DLabel",gunderma)
	metal:SetText("Metal: " .. metalamount)
	metal:SizeToContents()
	metal:SetPos(10,20)
	
	local xpos=10
	local ypos=50
	for k,v in pairs(GunPrices) do
		
			local SpawnIcon = vgui.Create("SpawnIcon",gunderma) -- The Vgui Elemnt is called SpawnIcon
			SpawnIcon:SetModel(ImgVars[k]) --Simply using SetModel for the model
			SpawnIcon:SetPos(xpos, ypos)
			print(k)
			SpawnIcon:SetToolTip("Metal Cost:".. v)
			xpos=xpos+SpawnIcon:GetWide()+10
			if(ypos>gunderma:GetWide()+SpawnIcon:GetWide()+10) then
				ypos=xpos+SpawnIcon:GetTall()+10
				xpos=30
			end

			SpawnIcon.DoClick= function(SpawnIcon,key)
						RunConsoleCommand("createweapon", k)
						gunderma:Close()
			end
	end


	--[[
	local pistol= vgui.Create("DImageButton",gunderma)
	pistol:SetImage("VGUI/entities/weapon_pistol")
	pistol:SetPos(10,50)
	pistol:SizeToContents()
	pistol.DoClick = function()	
		RunConsoleCommand("createweapon", "weapon_pistol")
		gunderma:Close()
	end	
	
	
	local w357= vgui.Create("DImageButton",gunderma)
	w357:SetImage("VGUI/entities/weapon_357")
	w357:SetPos(100,50)
	w357:SizeToContents()
	w357.DoClick = function()	
		RunConsoleCommand("createweapon", "weapon_357")
		gunderma:Close()
	end

	local ar2= vgui.Create("DImageButton",gunderma)
	ar2:SetImage("VGUI/entities/weapon_ar2")
	ar2:SetPos(190,50)
	ar2:SizeToContents()
	ar2.DoClick = function()	
		RunConsoleCommand("createweapon", "weapon_ar2")
		gunderma:Close()
	end	
	--]]

	
end

usermessage.Hook("buildweapon", buildweapon) 


